import java.util.Scanner;

/**
 * @Author YuanYuan
 * @Date 2022/5/30
 * @Time 11:33
 */
public class Test {
    public static final String name = "admin";
    public static final String code = "admin";

    public static void Login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入正确的用户名:");
        String username = scanner.nextLine();
        if(!username.equals(name)) {
            throw new NameException("用户名错误:"+username);
        }
        //String help = scanner.nextLine();
        System.out.println("请输入正确的密码:");
        String usercode = scanner.nextLine();
        if(!usercode.equals(code)) {
            throw new CodeException("密码错误: "+ usercode);
        }
        System.out.println("登陆成功!");
    }
    public static void Login1(String username,String usercode) {
        if(!username.equals(name)) {
            throw new NameException("用户名错误:"+username);
        }
        if(!usercode.equals(code)) {
            throw new CodeException("密码错误: "+ usercode);
        }
        System.out.println("登陆成功");
    }

    public static void main(String[] args) {
       // Login();
        try {
            Login1("admin","admi2");
        }catch (NameException e) {
            e.printStackTrace();
        }catch (CodeException e) {
            e.printStackTrace();
        }

    }
}
